package com.vanzo.ui;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.vanzo.adapter.MemberListRecyclerAdapter;
import com.vanzo.bean.MembersListBeen;
import com.vanzo.encryption.R;

import java.util.ArrayList;

/**
 * Created by yaofang on 2018/3/6.
 */

public class ChatDetailsActivity extends BaseActivity2 {

    private TextView mTitle;
    private EditText mChat;
    private RecyclerView mChatRecyalerview;

    @Override
    protected int getLayoutId() {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        return R.layout.activity_chat_details;
    }

    @Override
    protected void initView() {
        ImageView mBack = (ImageView) findViewById(R.id.goback);
        mBack.setVisibility(View.VISIBLE);
        mTitle = (TextView) findViewById(R.id.tv_title);
        mChat = (EditText) findViewById(R.id.ed_chat);
        Button mSendChat = (Button) findViewById(R.id.btn_send_chat);
        mChatRecyalerview = (RecyclerView) findViewById(R.id.chat_recyalerview);
        setGoBack(true);
    }

    @Override
    protected void initData() {
        String currentChat = getIntent().getStringExtra("currentChat");
        if (currentChat != null) {
            mTitle.setText(currentChat);
        }
        ArrayList<MembersListBeen> mMemberLists = new ArrayList<>();

        for (int i = 0; i < 20; i++) {
            MembersListBeen membersListBeen = new MembersListBeen();
            if (i == 0) {
                membersListBeen.setName("本组");
            } else {
                membersListBeen.setName("00" + i);
            }

            mMemberLists.add(membersListBeen);
        }
        mChatRecyalerview.setLayoutManager(new LinearLayoutManager(this));
        MemberListRecyclerAdapter memberListRecyclerAdapter = new MemberListRecyclerAdapter(this, mMemberLists);
        mChatRecyalerview.setAdapter(memberListRecyclerAdapter);
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void processClick(View v) {
        switch (v.getId()) {
            case R.id.goback:
                startChatActivity();
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            startChatActivity();
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

    private void startChatActivity() {
        Intent intent = new Intent(ChatDetailsActivity.this, HomeActivity.class);
        intent.putExtra("Message", 1);
        startActivity(intent);
        finish();
    }
}
